/*
Copyright Nicolas Dessart 2010 Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef H_TOKEN
#define H_TOKEN

#include <string>
#include <list>
#include <sstream>

enum Type
{
    Add,Mult,Min,Div,Pow,Fact,Equal, Sub,
    Val,Func, Ref,
    LPar,RPar,LBra,RBra,
    Space, Comma, Semico
};

template <typename T>
struct Token
{
    Token(Type t, T val = 0, std::string n = ""): type(t), value(val), name(n) {}
    Type type;
    T value;
    std::string name;

    std::string Print(void)
    {
        std::string s;
        std::ostringstream oss(s);
        switch (type)
        {
        case LPar :
            s = "(";
            break;
        case RPar :
            s = ")";
            break;
        case LBra :
            s = "[";
            break;
        case RBra :
            s = "]";
            break;
        case Comma :
            s = ",";
            break;
        case Semico :
            s = ";";
            break;
        case Add  :
            s = "+";
            break;
        case Mult :
            s = "*";
            break;
        case Min  :
            s = "-";
            break;
        case Equal:
            s = "=";
            break;
        case Div  :
            s = "/";
            break;
        case Pow  :
            s = "^";
            break;
        case Fact :
            s = "!";
            break;
        case Sub  :
            s = "_";
            break;
        case Val  :
            oss << value;
            s = oss.str();
            break;
        case Func :
            oss << name;
            s = oss.str();
            break;
        case Ref  :
            oss << name;
            s = oss.str();
            break;
        default   :
            s = "" ;
            break;
        }
        return s;
    }
};

//template <typename T>
//void PrintTokens(std::string& tokens, std::list<Token<T> > list)
//{
//    std::cout << std::endl;
//    for_each(list.begin(),list.end(),std::mem_fun_ref(&Token<T>::Print));
//    std::cout << std::endl;
//}

#endif
